const tools = {
    // 设备状态
    getCheckStatus: (key) => {
        switch(key){
            case 1:
                return '正常';
            case 2:
                return '故障';
        }
    },

    // 台账状态
    getAccountStatus: (key) => {
        switch(key){
            case 1:
                return '待审批';
            case 2:
                return '审批失败';
            case 3:
                return '启用';
            case 4:
                return '停用';
            default:
                return
        }
    },

    // 根据状态显示按钮
    showStatusText: (key) => {
        switch(key){
            case 2: 
                return "待企业审批";
            case 3: 
                return "待平台审核";
            case 4: 
                return "待接单";
            case 5: 
                return "待确认";
            case 6: 
                return "待领件";
            case 7: 
                return "待维修";
            case 8: 
                return "维修中";
            case 9: 
                return "待验收";
            case 10:
                return  "已完成";
            case 11:
                return  "取消中";
            case 12:
                return  "超时未完成";
            case 13:
                return  "企业审批失败";
            case 14:
                return  "已删除";
            default:
                return;
        }
    },

    // 清除缓存，刷新整个页面
    cleanCache: (key) => {
        if (key === 'repairSingle') {
            localStorage.removeItem('repairSingle')
            localStorage.removeItem('formData')
        }
        if (key === 'reformSingle') {
            localStorage.removeItem('reformSingle')
            localStorage.removeItem('reformData')
        }
        if (key === 'complainSingle') {
            localStorage.removeItem('complainSingle')
            localStorage.removeItem('complainData')
        }
    },

    // 清除维修单所有缓存，恢复到默认状态
    cleanCacheAll: (key) => {
        localStorage.removeItem('repairSingle')
        localStorage.removeItem('reformSingle')
        localStorage.removeItem('complainSingle')
        localStorage.removeItem('formData')
        localStorage.removeItem('reformData')
        localStorage.removeItem('complainData')
        localStorage.removeItem('repairTabsKey')
    },

    // 判断是否为JSON格式
    isJSON: (str) => {
        if (typeof str == 'string') {
            try {
                var obj=JSON.parse(str);
                if(typeof obj == 'object' && obj ){
                    return true;
                }else{
                    return false;
                }
    
            } catch(e) {
                return false;
            }
        }
    }
}

export default tools